package com.cleaningcloud.cld.controller;

import java.util.List;

import com.cleaningcloud.cld.domain.CldComplaintsReply;
import com.cleaningcloud.cld.domain.dto.CldComplaintsDto;
import com.cleaningcloud.cld.domain.vo.CldComplaintsVo;
import com.cleaningcloud.cld.service.ICldComplaintsReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import com.cleaningcloud.cld.domain.CldComplaints;
import com.cleaningcloud.cld.service.ICldComplaintsService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.page.TableDataInfo;

/**
 * 客诉与处置Controller
 * 
 * @author cleaningcloud
 * @date 2024-10-17
 */
@RestController
@RequestMapping("/complaints")
public class CldComplaintsController extends BaseController
{
    @Autowired
    private ICldComplaintsService cldComplaintsService;

    @Autowired
    private ICldComplaintsReplyService cldComplaintsReplyService;

    /**
     * 查询客诉与处置列表
     */
    @RequiresPermissions("cld:complaints:list")
    @GetMapping("/list")
    public TableDataInfo list(CldComplaintsDto cldComplaints)
    {
        startPage();
        List<CldComplaintsVo> list = cldComplaintsService.selectCldComplaintsList(cldComplaints);
        return getDataTable(list);
    }

    /**
     * 查询客诉与处置列表
     */
    @RequiresPermissions("cld:complaints:list")
    @GetMapping("/groupProjectList")
    public TableDataInfo groupProjectList(CldComplaintsDto cldComplaints)
    {
        startPage();
        List<CldComplaintsVo> list = cldComplaintsService.selectCldComplaintsGroupProjectList(cldComplaints);
        return getDataTable(list);
    }



    /**
     * 获取客诉与处置详细信息
     */
    @RequiresPermissions("cld:complaints:query")
    @GetMapping(value = "/{complaintsId}")
    public AjaxResult getInfo(@PathVariable("complaintsId") Long complaintsId)
    {
        return success(cldComplaintsService.selectCldComplaintsByComplaintsId(complaintsId));
    }

    /**
     * 新增客诉与处置
     */
    @RequiresPermissions("cld:complaints:add")
    @Log(title = "客诉与处置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CldComplaints cldComplaints)
    {
        return toAjax(cldComplaintsService.insertCldComplaints(cldComplaints));
    }

    /**
     * 新增客诉回复
     */
    @RequiresPermissions("cld:complaints:add")
    @Log(title = "客诉回复", businessType = BusinessType.INSERT)
    @PostMapping("/addReply")
    public AjaxResult addReply(@RequestBody CldComplaintsReply cldComplaintsReply)
    {
        return toAjax(cldComplaintsReplyService.insertCldComplaintsReply(cldComplaintsReply));
    }

    /**
     * 修改客诉与处置
     */
    @RequiresPermissions("cld:complaints:edit")
    @Log(title = "客诉与处置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CldComplaints cldComplaints)
    {
        return toAjax(cldComplaintsService.updateCldComplaints(cldComplaints));
    }

    /**
     * 删除客诉与处置
     */
    @RequiresPermissions("cld:complaints:remove")
    @Log(title = "客诉与处置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{complaintsIds}")
    public AjaxResult remove(@PathVariable Long[] complaintsIds)
    {
        return toAjax(cldComplaintsService.deleteCldComplaintsByComplaintsIds(complaintsIds));
    }
}
